/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CompanyInfo;
/*     */ import com.newcrm.bean.Group;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.DealManager;
/*     */ import com.newcrm.exception.DBException;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.sql.SQLException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Enumeration;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class ListAllDeals extends AbstractAction
/*     */ {
/*  38 */   private static Logger logger = Logger.getLogger(ListAllDeals.class
/*  39 */     .getName());
/*     */ 
/*     */   public ListAllDeals(AbstractHttpServlet servlet)
/*     */   {
/*  42 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  49 */     String customerIds = Util.getURLParameter(request
/*  50 */       .getParameter("CustomerIds"));
/*     */ 
/*  52 */     int offset = Util.getURLIntParameter(request.getParameter("Offset"));
/*     */ 
/*  54 */     int totalPages = Util.getURLIntParameter(request
/*  55 */       .getParameter("TotalPages"));
/*     */ 
/*  57 */     int dealStatus = Util.getURLIntParameter(request
/*  58 */       .getParameter("DealStatus"));
/*     */ 
/*  60 */     int categoryId = Util.getURLIntParameter(request
/*  61 */       .getParameter("CategoryId"));
/*     */ 
/*  64 */     String responsibleUserId = Util.getURLParameter(request
/*  65 */       .getParameter("ResponsibleUserId"));
/*     */ 
/*  68 */     String createDate = Util.getURLParameter(request
/*  69 */       .getParameter("CreateDate"));
/*     */ 
/*  72 */     String wonDate = Util.getURLParameter(request.getParameter("WonDate"));
/*     */ 
/*  74 */     User loginUser = getLoginUser(request);
/*     */ 
/*  76 */     if ("*".equals(responsibleUserId)) {
/*  77 */       responsibleUserId = "";
/*     */     }
/*     */ 
/*  82 */     String groupIds = "";
/*  83 */     if ((!loginUser.isAdmin) && (!loginUser.isGroupAdmin)) {
/*  84 */       responsibleUserId = loginUser.userId;
/*  85 */     } else if (!loginUser.isAdmin) {
/*  86 */       CompanyInfo company = super.getCompany(request);
/*  87 */       Group group = company.getGroupById(loginUser.groupId);
/*  88 */       if (group == null)
/*  89 */         groupIds = String.valueOf(loginUser.groupId);
/*     */       else {
/*  91 */         groupIds = group.getAllIds();
/*     */       }
/*     */     }
/*     */ 
/*  95 */     List filters = new ArrayList();
/*  96 */     Enumeration paramNames = request.getParameterNames();
/*  97 */     while (paramNames.hasMoreElements()) {
/*  98 */       String paramName = (String)paramNames.nextElement();
/*  99 */       String paramValue = Util.getURLParameter(request
/* 100 */         .getParameter(paramName));
/* 101 */       if (paramName.contains("_"))
/*     */       {
/* 104 */         if ((paramValue != null) && (paramValue.trim().length() != 0))
/*     */         {
/* 107 */           String[] splitValue = paramName.split("_");
/* 108 */           if (splitValue.length == 3)
/*     */           {
/* 111 */             String[] filter = new String[3];
/* 112 */             filter[0] = splitValue[0];
/* 113 */             filter[1] = splitValue[1];
/* 114 */             filter[2] = paramValue;
/* 115 */             filters.add(filter);
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/* 118 */     DealManager manager = new DealManager();
/*     */ 
/* 120 */     response.setContentType("text/html;charset=utf-8");
/* 121 */     PrintWriter out = response.getWriter();
/* 122 */     JSONObject jsonObject = new JSONObject();
/*     */     try {
/* 124 */       if ((customerIds == null) || (customerIds.trim().length() == 0)) {
/* 125 */         String showWonTotalInfo = Util.getURLParameter(request
/* 126 */           .getParameter("ShowWonTotalInfo"));
/*     */ 
/* 129 */         if ("1".equals(showWonTotalInfo)) {
/* 130 */           List result = manager
/* 131 */             .listWonDealsTotalInfo(loginUser.isAdmin, 
/* 132 */             dealStatus, categoryId, responsibleUserId, 
/* 133 */             groupIds, createDate, wonDate, filters, 
/* 134 */             loginUser.userId, loginUser.companyId);
/* 135 */           if ((result != null) && (result.size() > 0)) {
/* 136 */             jsonObject.put("totalMoney", 
/* 137 */               ((Map)result.get(0)).get("totalMoney"));
/* 138 */             jsonObject.put("totalWonNum", 
/* 139 */               ((Map)result.get(0)).get("totalWonNum"));
/* 140 */             jsonObject.put("totalCommission", 
/* 141 */               ((Map)result.get(0)).get("totalCommission"));
/*     */           }
/* 143 */           jsonObject.put("error", "0");
/* 144 */           out.println(jsonObject);
/* 145 */           out.flush();
/* 146 */           out.close();
/* 147 */           return;
/*     */         }
/*     */ 
/* 151 */         int totalNums = 0;
/* 152 */         if (totalPages < 1) {
/* 153 */           totalNums = manager.listAllCount(loginUser.isAdmin, 
/* 154 */             dealStatus, categoryId, responsibleUserId, 
/* 155 */             groupIds, createDate, wonDate, filters, 
/* 156 */             loginUser.userId, loginUser.companyId);
/* 157 */           totalPages = totalNums / 10;
/* 158 */           if (totalNums % 10 > 0) {
/* 159 */             totalPages++;
/*     */           }
/*     */         }
/*     */ 
/* 163 */         List result = manager.listAll(
/* 164 */           loginUser.isAdmin, dealStatus, categoryId, 
/* 165 */           responsibleUserId, groupIds, createDate, wonDate, 
/* 166 */           filters, loginUser.userId, offset, 10, 
/* 167 */           loginUser.companyId);
/* 168 */         jsonObject.put("error", "0");
/* 169 */         jsonObject.put("deals", result);
/* 170 */         jsonObject.put("totalNums", Integer.valueOf(totalNums));
/* 171 */         jsonObject.put("totalPages", Integer.valueOf(totalPages));
/*     */       }
/*     */       else
/*     */       {
/* 175 */         List result = manager
/* 176 */           .listCustomerDeals(customerIds);
/* 177 */         jsonObject.put("error", "0");
/* 178 */         jsonObject.put("deals", result);
/*     */       }
/*     */     } catch (DBException e) {
/* 181 */       jsonObject.put("error", "1");
/* 182 */       logger.warn("list all deals failed", e);
/*     */     } catch (SQLException e) {
/* 184 */       jsonObject.put("error", "1");
/* 185 */       logger.warn("list all deals failed", e);
/*     */     }
/* 187 */     out.println(jsonObject);
/* 188 */     out.flush();
/* 189 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ListAllDeals
 * JD-Core Version:    0.6.1
 */